const msqlFile = require('../assets/js/commnMySQL');
const connection = msqlFile.sqlConnection;

module.exports = {
   getCategories(callback){
     let sql = `SELECT * FROM categories`;
     connection.query(sql,(err,result)=>{
       callback(err,result);
     });
   },
   addNewCategories(data,callback){
    let sql = `INSERT INTO categories SET \`NAME\`='${data.name}',slug='${data.slug}',classname='${data.classname}'`;
    connection.query(sql,(err,result)=>{
      callback(err,result);
    });
  },
  getCategoriesById(id,callback){
    let sql = `SELECT * FROM categories WHERE id=${id}`;
    connection.query(sql,(err,result)=>{
      callback(err,result[0]);
    });
  },
  delCategoriesById(id,callback){
    let sql = `DELETE FROM categories WHERE id=${id}`;
    connection.query(sql,(err,result)=>{
      callback(err,result);
    });
  },
  editCategories(id,data,callback){
  let sql = `UPDATE categories SET ? WHERE id=${id}`
    connection.query(sql,data,(err,result)=>{
      callback(err,result);
    });
  },
  deletemultiple(ids,callback){
    let  data = ids.join();
    let sql = `DELETE FROM categories WHERE id in (${data})`;
  //  console.log(sql);
  connection.query(sql,(err,result)=>{
    callback(err,result);
  });
  },
  getNavigation(callback){
    let sql = `SELECT * FROM categories WHERE isShow=1`;
    connection.query(sql,(err,result)=>{
      callback(err,result);
    });
  },
  hideNavigation(id,callback){
    let sql = `UPDATE categories set isShow=0 WHERE id=${id}`;
    connection.query(sql,(err,result)=>{
      callback(err,result);
    });
  },
  showNavigation(id,callback){
    let sql = `UPDATE categories set isShow=1 WHERE id=${id}`;
    connection.query(sql,(err,result)=>{
      callback(err,result);
    });
  }

};